<?php
namespace Home\Controller;
session_start();

class LoginController extends HomeController {
    public function index(){
        $this->show();
    }

               // 生成验证码

    public function yzm()
    {
        $verify = new \Think\Verify();
        $verify->fontSize = '18';
        $verify->length = '4';
        $verify->imageW = '150';
        $verify->imageH = '36';
        $verify->useCurve = true;
        $verify->useNoise = false;
        $verify->codeSet ="0123456789";
        $verify->entry();

    }

    public function log(){
        $user=M('user');
        $code = I('post.code');
        $verify = new \Think\Verify();
        if($verify->check($code,$id="")){
            $arr['email'] = $_POST['email'];
            $arr['password'] = $_POST['pwd'];
            $data=$user->where($arr)->find();
            if($data>0){
                    // var_dump($_SESSION);die;
                    $user_msg = M('user')->table('dota2_user u,dota2_user_info ui')->field('u_id,nickname')->where('u.u_id=ui.ui_id and email="'.$_POST['email'].'"')->find();
                    $_SESSION['nickname'] = $user_msg['nickname'];
                    $_SESSION['uid'] = $user_msg['u_id'];
                    $_SESSION['email'] = $_POST['email'];
                    // dump($_SESSION);die;
                    $this-> success('登录成功',U('Index/index'));
                }else{
                $this->error('用户名或密码错误');
                return false;
            }
        }else{
            $this->error('验证码错误');
            return false;
        }
    }
    
}